package info.ask4research.model;

import info.ask4research.model.activities.Activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@JsonAutoDetect
@Entity
@Table(name="UnitOfLearning")
public class UnitOfLearning {

	@Id
	@GeneratedValue
	@Column(name="unitoflearning_ID")
	private int id;
	@Column(name="title", nullable=false)
	private String title;
	@Column(name="version")
	private int version;

	@OneToMany(cascade=CascadeType.REMOVE)
	@JoinTable(name = "UnitOfLearningActivities", joinColumns = {
			@JoinColumn(name="unitoflearning_ID", unique = false, updatable=true) },	inverseJoinColumns = {
			@JoinColumn(name="activity_ID", unique = false, updatable=true)
						}
			)
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Activity> activity = new ArrayList<Activity>();
	@OneToOne
	@JoinColumn(name="Author_id", unique=false, nullable=false, updatable=false)
	private User author;
	@OneToOne
	@JoinColumn(name="Graph_id", unique=false, nullable=true, updatable=true)
	private Graph graph;
	@Column(name="subject")
	private String subject;
	@Column(name="description")
	private String description;
	

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public int getVersion() {
		return version;
	}
	public void setVersion(int version) {
		this.version = version;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	//	public Level getLevel() {
	//		return level;
	//	}
	//	public void setLevel(Level level) {
	//		this.level = level;
	//	}
	//	public User getAuthor() {
	//		return author;
	//	}
	public void setAuthor(User author) {
		this.author = author;
	}
	public List<Activity> getActivity() {
		return activity;
	}
	public void setActivity(List<Activity> activity) {
		this.activity = activity;
	}
	public void addActivity(Activity activity) {
		this.activity.add(activity);
	}
	public void removeActivity(Activity activity) {
		this.activity.remove(activity);
	}
	public Graph getGraph() {
		return graph;
	}
	public void setGraph(Graph graph) {
		this.graph = graph;
	}
}
